#include "stdafx.h"
#include "../aclib/HexParser.h"

namespace AC = AppliedCryptography;
using ::testing::Return;

TEST(AESDecrypt, 128bitKey)
{
	AC::AES::Decryptor<AC::AES::key128bit> aes;
	AC::AES::Key<AC::AES::key128bit> key;
	AC::AES::Plaintext plain;
	AC::AES::Chypertext chyper;
	AC::HexParser hx;

	ASSERT_NO_THROW({
		key.Set(hx("95A8EE8E89979B9EFDCBC6EB9797528D"));
	});

	ASSERT_NO_THROW({
		plain.Set(hx("4EC137A426DABF8AA0BEB8BC0C2B89D6"));
	});

	ASSERT_NO_THROW({
		aes.SetKey(key);
	});

	ASSERT_NO_THROW({
		aes.Process(plain, chyper);
	});

	EXPECT_TRUE(hx("9570C34363565B393503A001C0E23B65") == chyper.Get()) << "  chyper: " << hx(chyper.Get());
};

TEST(AESDecrypt, 192bitKey)
{
	AC::AES::Decryptor<AC::AES::key192bit> aes;
	AC::AES::Key<AC::AES::key192bit> key;
	AC::AES::Plaintext plain;
	AC::AES::Chypertext chyper;
	AC::HexParser hx;

	ASSERT_NO_THROW({
		key.Set(hx("95A8EE8E89979B9EFDCBC6EB9797528D432DC26061553818"));
	});

	ASSERT_NO_THROW({
		plain.Set(hx("4EC137A426DABF8AA0BEB8BC0C2B89D6"));
	});

	ASSERT_NO_THROW({
		aes.SetKey(key);
	});

	ASSERT_NO_THROW({
		aes.Process(plain, chyper);
	});

	EXPECT_TRUE(hx("29DFD75B85CEE4DE6E26A808CDC2C9C3") == chyper.Get()) << "  chyper: " << hx(chyper.Get());
};

TEST(AESDecrypt, 256bitKey)
{
	AC::AES::Decryptor<AC::AES::key256bit> aes;
	AC::AES::Key<AC::AES::key256bit> key;
	AC::AES::Plaintext plain;
	AC::AES::Chypertext chyper;
	AC::HexParser hx;

	ASSERT_NO_THROW({
		key.Set(hx("95A8EE8E89979B9EFDCBC6EB9797528D432DC26061553818EA635EC5D5A7727E"));
	});

	ASSERT_NO_THROW({
		plain.Set(hx("4EC137A426DABF8AA0BEB8BC0C2B89D6"));
	});

	ASSERT_NO_THROW({
		aes.SetKey(key);
	});

	ASSERT_NO_THROW({
		aes.Process(plain, chyper);
	});

	EXPECT_TRUE(hx("110A3545CE49B84BBB7B35236108FA6E") == chyper.Get()) << "  chyper: " << hx(chyper.Get());
};

